package com.fushenlan.epidemicControl.controller;


import com.fushenlan.Vo.EmergencyVO;
import com.fushenlan.commons.GeneralResponse;
import com.fushenlan.epidemicControl.dto.EmergencyDTO;

import com.fushenlan.epidemicControl.service.EmergencyService;

import com.fushenlan.po.Emergency;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.UUID;


/**
 * @ClassNameEmergencyController
 * @Description TODO
 * @Author17918
 * @Date2022/4/22
 * @Version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/emer")
public class EmergencyController {

    @Autowired
    private EmergencyService emergencyService;


    /**
     * 发起紧急救助
     *
     * @param emergencyDTO
     * @return
     */
    @ApiOperation("居民发起紧急救助")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public GeneralResponse insert(@RequestBody EmergencyDTO emergencyDTO) {

        return emergencyService.commitEmergency(emergencyDTO);
    }

    /**
     * 个人查看紧急救助
     *
     * @param
     * @return
     */
    @ApiOperation("个人查看紧急救助")
    @RequestMapping(value = "/listByUserId", method = RequestMethod.POST)
    public GeneralResponse<List<EmergencyDTO>> list(@RequestParam String userId) {
        return emergencyService.getListByUserId(userId);
    }

    /**
     * 居委根据条件查看紧急救助
     *
     * @param
     * @return
     */
    @ApiOperation(value = "居委根据条件查看紧急救助",notes = "level{紧急程度1紧急，2叫急，3一般}，state{1未处理，3已处理，}；neighborhoodId所属居委id，inhabitantId该居委inhabitantId")
    @RequestMapping(value = "/listByType", method = RequestMethod.POST)
    public GeneralResponse listByType(@RequestParam String level, @RequestParam String state,@RequestParam String neighborhoodId,@RequestParam String inhabitantId,@RequestParam String userName) {

        return emergencyService.getListByStateAndType(state, level,neighborhoodId,inhabitantId,userName);

    }
    /**
     * 居委根据条件查看紧急救助
     *
     * @param
     * @return
     */
    @ApiOperation("查看紧急救助详情")
    @RequestMapping(value = "/info", method = RequestMethod.POST)
    public GeneralResponse<EmergencyVO> info(@RequestParam String id) {

        return emergencyService.getInfoById(id);

    }

    /**
     * 居委处理紧急救助
     *
     * @param
     * @return
     */
    @ApiOperation("居委处理紧急救助")
    @RequestMapping(value = "/deal", method = RequestMethod.POST)
    public GeneralResponse deal(@RequestParam String result, @RequestParam String id,@RequestParam String dealUserId) {

        return emergencyService.deal(id, result,dealUserId);

    }

    /**
     * 上传附件
     *
     * @param
     * @return
     */

    @ApiOperation("上传附件")
    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    public GeneralResponse upload(@RequestParam MultipartFile file,@RequestParam String id) {

        emergencyService.upload(file,id);
        return GeneralResponse.success();

    }





}
